var wsUrl = 'ws://napi.6scx.com/lscx/socket/passenger/'; //长链接地址

var userId = uni.getStorageSync('userInfo').id || false;

var socketTask = null;

var ws = {
	socketTask: null,
	init
}

function init() {	
	
	uni.closeSocket({
		complete(e) {
			// console.log(e)
		}
	})
	
	socketTask = uni.connectSocket({
		url: wsUrl + userId,
		// url: 'ws://napi.6scx.com/lscx/socket/passenger/207',
		complete: () => {}
	})
	
	socketTask.onError(function(res){
		// console.log(res);
		// console.log('连接失败，正在重新连接...');
		socketTask.close();
		init();
	})
	ws.socketTask = socketTask;
}

module.exports = ws;
